<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <input type="text" placeholder="请输入你要猜的数字(1-100)">
    <input type="button" value="猜一下" onclick="f()">
    <h3>结果：<span></span></h3>
</body>
<script>
    //得到一个1-100之间的随机数
    let num= parseInt(Math.random()*100) + 1;
    //获取文本框输入的数和span的内容
    let i = document.querySelector("input");
    let s = document.querySelector("span");

    function f() {
        if (i.value > num){
            s.innerText = "猜大了！";
        } else if (i.value < num){
            s.innerText = "猜小了！";
        } else {
            s.innerText = "恭喜老铁，猜对了！";
        }
    }
</script>
</html>
